<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组和对象的解构</title>
</head>
<body>
  <script>
    //数组的解构
    var names = ["abcx", undefined, "cbna", 123, "433"]
    console.log(names[0])
    console.log(names[1])
    console.log(names[2])

    var [name1, name2, name3] = names
    console.log(name1)
    console.log(name2)
    console.log(name3)

    var [name1, name2 = "default", name3 = "default1"] = names
    console.log(name1)
    console.log(name2)
    console.log(name3)

    //对象的解构
    var obj = { name: "why", age: 18, height: 1.88 }
    // 2.2. 顺序问题: 对象的解构是没有顺序, 根据key解构
    var {age, name}  = obj
    console.log(age)
    console.log(name)

     // 应用: 在函数中(其他类似的地方)
     function getPosition({ x, y }) {
      console.log(x, y)
    }

    getPosition({ x: 10, y: 20 })
    
  </script>
</body>
</html>